package com.chaos.meta.config;

import org.springframework.security.authentication.AuthenticationDetailsSource;
import org.springframework.security.web.authentication.WebAuthenticationDetails;

import javax.servlet.http.HttpServletRequest;

//@Component
public class CustomAuthenticationDetailsSource implements AuthenticationDetailsSource<HttpServletRequest, WebAuthenticationDetails> {
    static class CustomWebAuthenticationDetails extends WebAuthenticationDetails {
        private final String otherInfo;
        public CustomWebAuthenticationDetails(HttpServletRequest request) {
            super(request);
            this.otherInfo = request.getParameter("otherInfo");
        }

        public String getOtherInfo() {
            return otherInfo;
        }

        @Override
        public String toString() {
            StringBuilder sb = new StringBuilder();
            sb.append(super.toString()).append("; otherInfo: ").append(this.getOtherInfo());
            return sb.toString();
        }
    }

    @Override
    public WebAuthenticationDetails buildDetails(HttpServletRequest context) {
        return new CustomWebAuthenticationDetails(context);
    }
}